<?php
require_once("AbstractService.php");
require_once("dao/ObserverUpdateObjectDAO.php");
require_once("dao/ObserverUpdateDataDAO.php");


abstract class AbstractObservableService extends AbstractService{
	protected function insertObserverUpdate($serviceId, $requestId, $resultParams, $expiredTime, $clientIdList){
		$observerUpdateDataDAO = new ObserverUpdateDataDAO();
		$maxId = $observerUpdateDataDAO->selectMaxObserverUpdateDataId();
		$observerUpdateDataId = intval($maxId, 10) + 1;
		
		$jsonParams = json_encode($resultParams);
		$jsonParams = str_replace("\\", "\\\\", $jsonParams);
		
		$observerUpdateDataDAO->insertObserverUpdateData(
			$observerUpdateDataId, $serviceId, 
			$requestId, $jsonParams, $expiredTime);
		
		$observerUpdateObjectDAO = new ObserverUpdateObjectDAO();
		
		foreach ($clientIdList as $clientId){
			$observerUpdateObjectDAO->insertObserverUpdateObject($clientId, $observerUpdateDataId);
		}
	}
}
?>